package jdbc;

import java.sql.*;
import java.util.ArrayList;

/**
 * @author oldliu
 * @since 1.0
 */
public class MetaInformation {
    public int add(int a,int b){
        ArrayList l=null;
        try{
            return a+b;
        }
        catch(Exception e){
            System.out.println("catch语句块");
        }
        finally{
            System.out.println("finally语句块");
        }
        return 0;
    }

    public static void main(String[] args) {

        Connection connection = DBUtil.getConnection();
        try {
            DatabaseMetaData cm = connection.getMetaData();
            System.out.println(cm.getDatabaseProductName()+","+cm.getDatabaseProductVersion());
            System.out.println(cm.getDriverName());
            System.out.println(cm.getMaxConnections()+":最多连接数");
            System.out.println(cm.getUserName()+":连接用户");
            PreparedStatement ps=connection.prepareStatement("select * from s_student");
            ResultSet rs = ps.executeQuery();
            ResultSetMetaData metaData = rs.getMetaData();
            System.out.println("总共有列："+metaData.getColumnCount());
            for(int i=1;i<=metaData.getColumnCount();i++){
                System.out.println("列名："+metaData.getColumnLabel(i)+",类型:"+metaData.getColumnTypeName(i)+",对应的java类型："+metaData.getColumnClassName(i)+",自增长？"+metaData.isAutoIncrement(i));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
